//
//  MDHURLParameters.m
//  MDHPT
//
//  Created by 高得华 on 2019/4/23.
//  Copyright © 2019年 高得华. All rights reserved.
//

#import "MDHURLParameters.h"
#import "MDHHTTPService.h"

@implementation MDHURLExtendsParameters

+ (MDHURLExtendsParameters *)extendsParameters
{
    return [[self alloc] init];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

- (NSString *)version {
    static NSString *version = nil;
    if (version.length <= 0) {
        if (version == nil) version = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
        version = (version.length>0)?version:@"";
        //version = [version stringByReplacingOccurrencesOfString:@"." withString:@""];
    }
    return version;
}

- (NSString *)authorization {
    //    NSString *uid = self.uid;
    //    if (MHStringIsNotEmpty(uid) && MHStringIsNotEmpty([MHHTTPService sharedInstance].token)){
    //        NSString *t_token = [NSString stringWithFormat:@"%@-%@",uid,[MHHTTPService sharedInstance].token];
    //        return t_token;
    //    }
    return [MDHHTTPService sharedInstance].token;
}

- (NSString *)token {
    return [self authorization];
}

- (NSString *)deviceId {
    static NSString *deviceidStr = nil;
    if (deviceidStr == nil) deviceidStr = [SAMKeychain deviceId];
    return deviceidStr.length>0 ? deviceidStr:@"";
}

- (NSString *)device_id {
    return [self deviceId];
}

- (NSString *)source {
    return @"ios";
}

- (NSString *)channel {
    return @"AppStore";
}

/// 13位的时间戳
- (NSString *)t {//@"1234567890111";//
    return [NSString stringWithFormat:@"%.f", [NSDate date].timeIntervalSince1970*1000];
}

@end

@implementation MDHURLParameters

+(instancetype)urlParametersWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters
{
    return [[self alloc] initUrlParametersWithMethod:method path:path parameters:parameters];
}

-(instancetype)initUrlParametersWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters
{
    self = [super init];
    if (self) {
        self.method = method;
        self.path = path;
        self.parameters = parameters;
        self.extendsParameters = [[MDHURLExtendsParameters alloc] init];
    }
    return self;
}

@end


